//
//  SISSRecommandHouseCell.m
//  SISSAPP
//
//  Created by 优房网 on 2017/5/5.
//  Copyright © 2017年 优房网. All rights reserved.
//

#import "SISSRecommandHouseCell.h"

@interface SISSRecommandHouseCell ()



@property (strong, nonatomic) IBOutletCollection(UILabel) NSArray *markLabels;

@property (weak, nonatomic) IBOutlet UILabel *neighbourhoodAndPriceLabel;
@property (weak, nonatomic) IBOutlet UILabel *regionAreaTypeLabel;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *labelsViewHeight;
@property (weak, nonatomic) IBOutlet UIButton *checkButton;
@property (weak, nonatomic) IBOutlet UIImageView *offlineImageView;
@property (weak, nonatomic) IBOutlet UILabel *visibleLabel;

@end
@implementation SISSRecommandHouseCell


- (void)setHouseResourceModel:(SISSHouseResourceModel *)houseResourceModel {
    _houseResourceModel = houseResourceModel;
    
    self.neighbourhoodAndPriceLabel.text = [NSString stringWithFormat:@"%@ | %@万",houseResourceModel.neighbourhood,houseResourceModel.price];
    
    self.regionAreaTypeLabel.text = [NSString stringWithFormat:@"%@-%@ | %@㎡ | %@",houseResourceModel.region,houseResourceModel.regionDetail,[PublicUtil returnTwoDeciDecimalFormatter:houseResourceModel.area],houseResourceModel.houseType];
    
    if (houseResourceModel.read == 1) {
        self.neighbourhoodAndPriceLabel.textColor = [UIColor grayColor];
        self.regionAreaTypeLabel.textColor = [UIColor grayColor];
    }
    self.offlineImageView.hidden = houseResourceModel.houseresType == 1;
    
    if (houseResourceModel.listTag.count > 0) {
        self.labelsViewHeight.constant = 30;
    } else {
        self.labelsViewHeight.constant = 1;
    }
    
    for (UILabel *label in self.markLabels) {
        
        label.hidden = YES;
    }
    
    NSArray<UIColor *> *labelCololors = @[COLOR(0x33B189), COLOR(0xF76D81), COLOR(0x8E7FFF), COLOR(0x59ABFD), COLOR(0xE46B00)];
    
    for (int i = 0; i < houseResourceModel.listTag.count; i++) {
        UILabel *label = self.markLabels[i];
        if ([houseResourceModel.listTag[i].tag isEqualToString:@""]) continue;
        label.hidden = NO;
        label.layer.borderWidth = 1;
        label.text = [NSString stringWithFormat:@" %@ ",houseResourceModel.listTag[i].tag];;
        NSInteger colorIndex = houseResourceModel.listTag[i].color - 1;
        label.layer.borderColor = labelCololors[colorIndex].CGColor;
        label.textColor = labelCololors[colorIndex];
        label.layer.cornerRadius = 2;
        label.layer.masksToBounds = YES;
    }
    
    self.checkButton.selected = houseResourceModel.isSelected;
}

- (void)setIsChooseMain:(BOOL)isChooseMain {
    _isChooseMain = isChooseMain;
    
    NSString *imageName = isChooseMain ? @"mainCheckSelected" : @"checkSelected";
    [self.checkButton setImage:[UIImage imageNamed:imageName] forState:UIControlStateSelected];
}

//- (void)setHouseCooperationModel:(SISSHouseCooperationDetailModel *)houseCooperationModel {
//    _houseCooperationModel = houseCooperationModel;
//    
//    self.neighbourhoodAndPriceLabel.text = [NSString stringWithFormat:@"%@ | %.f万",houseCooperationModel.neighbourhood,houseCooperationModel.price];
//    
//    self.regionAreaTypeLabel.text = [NSString stringWithFormat:@"%@-%@ | %ld㎡ | %@",houseCooperationModel.region,houseCooperationModel.regionDetail,(long)houseCooperationModel.area,houseCooperationModel.houseType];
//    
//    //    if (houseCooperationModel.read == 1) {
//    //        self.neighbourhoodAndPriceLabel.textColor = [UIColor grayColor];
//    //        self.regionAreaTypeLabel.textColor = [UIColor grayColor];
//    //    }
//    
//    if (houseCooperationModel.listTag.count > 0) {
//        self.labelsViewHeight.constant = 20;
//    } else {
//        self.labelsViewHeight.constant = 1;
//    }
//    
//    NSArray<UIColor *> *labelCololors = @[COLOR(0x33B189), COLOR(0xF76D81), COLOR(0x8E7FFF), COLOR(0x59ABFD), COLOR(0xE46B00)];
//    
//    for (int i = 0; i < houseCooperationModel.listTag.count; i++) {
//        UILabel *label = self.markLabels[i];
//        if ([houseCooperationModel.listTag[i].tag isEqualToString:@""]) continue;
//        label.hidden = NO;
//        label.layer.borderWidth = 1;
//        label.text = houseCooperationModel.listTag[i].tag;
//        NSInteger colorIndex = houseCooperationModel.listTag[i].color - 1;
//        label.layer.borderColor = labelCololors[colorIndex].CGColor;
//        label.textColor = labelCololors[colorIndex];
//        label.layer.cornerRadius = 2;
//        label.layer.masksToBounds = YES;
//    }
//    
//}



- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.visibleLabel.hidden = YES;
    self.visibleLabel.text = @"";
}

- (IBAction)checkButtonAction:(id)sender {
    
    if ([self.delegate respondsToSelector:@selector(recommandHouseResourceCell:checkButtonIsSelected:)]) {
        BOOL doSelection = [self.delegate recommandHouseResourceCell:self checkButtonIsSelected:!self.checkButton.isSelected];
        if(!doSelection){
            
        }else{
            self.houseResourceModel.isSelected = !self.houseResourceModel.isSelected;
            self.checkButton.selected = self.houseResourceModel.isSelected;
        }
        
    }
    
}

@end
